﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using OgilvyOne.BLL;
using OgilvyOne.Model;

using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Model;
using System.Collections.Generic;
using ECCIT;
using ECCIT.Web;

public partial class admin_UKNOW_event_event_list : AdminBasePage
{
    private const string VIEWSTATE_LAYER_ID = "layerid";
    private const string VIEWSTATE_COLUMN_ID = "columnid";
    private const string VIEWSTATE_PAGE_NO = "pageNum";
    //mff
    private const string VIEWSTATE_COLUMN_ISSPECIAL = "IsSpecial";
    private int operatetype
    {
        get { return (int)this.ViewState["operatetype"]; }
        set { this.ViewState.Add("operatetype", value); }
    }
    //mff
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!Page.IsPostBack)
        {
            operatetype = 1;
            ViewState[VIEWSTATE_LAYER_ID] = Request.Params[VIEWSTATE_LAYER_ID];
            ViewState[VIEWSTATE_COLUMN_ID] = Request.Params[VIEWSTATE_COLUMN_ID];
            //mff
            ViewState[VIEWSTATE_COLUMN_ISSPECIAL] = Request.QueryString[VIEWSTATE_COLUMN_ISSPECIAL] != null ? Request.QueryString[VIEWSTATE_COLUMN_ISSPECIAL] : string.Empty;
            //mff
            this.headers.Text = new ColumnBll().LayeridColumnConNaiv(Request.Params[""]);
           // ViewState[VIEWSTATE_PAGE_NO] = "1";//如果不是回发,即首次加载页面,则令,ViewState[VIEWSTATE_PAGE_NO] = "1",页面显示的是GridView1的第一页;
            hdnPopupUrl.Value = GetPopupUrl();
            Grid_viewBild();
        }
        //else
        //{
        //    if (string.IsNullOrEmpty(ViewState[VIEWSTATE_PAGE_NO].ToString())) return;
        //    string sPageNum = Request.Params[VIEWSTATE_PAGE_NO];
        //    if (ViewState[VIEWSTATE_PAGE_NO].ToString() != sPageNum)
        //    {
        //        ViewState[VIEWSTATE_PAGE_NO] = sPageNum;
        //        Grid_viewBild();
        //    }
        //}
    }

    private string ReturnQueryString(bool b)
    {
        string url = string.Format("{0}{1}={2}&{3}={4}&{5}={6}&{7}={8}", (b ? "?" : ""), 
            VIEWSTATE_LAYER_ID, ViewState[VIEWSTATE_LAYER_ID], 
            VIEWSTATE_COLUMN_ID, ViewState[VIEWSTATE_COLUMN_ID],
            "langID", this.LangID,
            VIEWSTATE_COLUMN_ISSPECIAL, ViewState[VIEWSTATE_COLUMN_ISSPECIAL]
            );
        return url;
    }

    private string GetPopupUrl()
    {
        string url = string.Format("../seo.aspx?{0}={1}&{2}={3}",//&{4}={5}
            VIEWSTATE_COLUMN_ID, ViewState[VIEWSTATE_COLUMN_ID],
            //VIEWSTATE_LAYER_ID, ViewState[VIEWSTATE_LAYER_ID],
            "langID", this.LangID);
        return url;
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Grid_viewBild();
        // BindData();
    }
    private void Grid_viewBild()
    { 
        int columnid = int.Parse(Request.Params["columnid"]); 
        ColumnModel cm = new ColumnBll().GetColumn(columnid);
        IList<EventsModel> eventsls = null;
        if (!string.IsNullOrEmpty(ViewState[VIEWSTATE_COLUMN_ISSPECIAL] != null ? ViewState[VIEWSTATE_COLUMN_ISSPECIAL].ToString() : string.Empty))
        {
            int isspecial;
            if(int.TryParse(ViewState[VIEWSTATE_COLUMN_ISSPECIAL].ToString(),out isspecial))
            {
                eventsls = new EventsBLL(LangID).AfterGetAllEventsModels(isspecial);
            }       

        }
        else
        {
            eventsls = new EventsBLL(LangID).AfterGetAllEventsModels();
        }
        if (eventsls != null && eventsls.Count>0)
        {
            GridView1.DataSource =
                eventsls.Skip((AspNetPager1.CurrentPageIndex - 1)*AspNetPager1.PageSize).Take(AspNetPager1.PageSize).
                    ToList(); //eventsls;
           // GridView1.PageIndex = int.Parse(ViewState[VIEWSTATE_PAGE_NO].ToString()) - 1;
            GridView1.DataBind();
            this.AspNetPager1.RecordCount = eventsls.Count;
        }
        // this.pagehtml.Text = getPageHtml(GridView1.PageCount, GridView1.PageIndex + 1, eventsls.Count);
    }
    /*修改人：穆凤凤
         * 修改时间：2012-03-06
         * 修改内容：
         *      新增加方法 绑定按姓名查找出来的活动记录 Grid_viewBildPart
         *      有mff注释的为本次修改的代码
         */
    //mff
    //按活动名称搜索活动记录
    protected void Grid_viewBildPart(object sender, EventArgs e)
    {
        operatetype = 2;
        string ename = eventName.Text;
        int? state = Convert.ToInt32(eventState.SelectedValue);
        //将是否为特色活动的标识,传入到DAL层的搜索方法中
        int? isspecial = null;
        if (ViewState[VIEWSTATE_COLUMN_ISSPECIAL] != null && !string.IsNullOrEmpty(ViewState[VIEWSTATE_COLUMN_ISSPECIAL].ToString()))
        {
            isspecial = Convert.ToInt32(ViewState[VIEWSTATE_COLUMN_ISSPECIAL]);
        }
        int columnid = int.Parse(Request.Params["columnid"]);
        ColumnModel cm = new ColumnBll().GetColumn(columnid);
        IList<EventsModel> searchEventByName = new EventsBLL(LangID).AfterGetEventsModelByName(ename, state, isspecial);
        if (searchEventByName != null && searchEventByName.Count>0)
        {
            GridView1.DataSource =
                searchEventByName.Skip((AspNetPager1.CurrentPageIndex - 1)*AspNetPager1.PageSize).Take(
                    AspNetPager1.PageSize).
                    ToList();
            //GridView1.PageIndex= int.Parse(ViewState[VIEWSTATE_PAGE_NO].ToString()) - 1;
            GridView1.DataBind();
            this.AspNetPager1.RecordCount = searchEventByName.Count;
        }
        //this.pagehtml.Text = getPageHtml(GridView1.PageCount, GridView1.PageIndex + 1, searchEventByName.Count);
        eventName.Text = "";
        eventState.SelectedValue = "2";
    }
    //mff
    protected void Add_click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("event_add.aspx{0}", ReturnQueryString(true)), true);
    }

    protected void Del_click(object sender, EventArgs e)
    {
        int eid = int.Parse(((LinkButton)sender).CommandArgument);
        ResultInfo res = new EventsBLL(LangID).delEvent(eid);
        if(res.Result)
        {
            Response.Write("<script>alert('"+res.Message+"')</script>");
        }
        else
        {
            Response.Write(res.Message);
        }
        //删除该活动下的所有图片和视频以及数据库中的记录
        //删除活动表里该活动的记录
        Grid_viewBild();
    }

    protected void Pubone_click(object sender, EventArgs e)
    {
        //修改单个活动的发布状态
        int eid =int.Parse(((LinkButton)sender).CommandArgument);
        new EventsBLL(LangID).modPubOne(eid);
        Grid_viewBild();
    }
    protected void setSpecial_click(object sender, EventArgs e)
    {
        //设置单个活动是否为特色活动
        int eid = int.Parse(((LinkButton)sender).CommandArgument);
        new EventsBLL(LangID).modSetSpecial(eid);
        Grid_viewBild();
    }
    protected void Mod_click(object sender, EventArgs e)
    {
        Response.Redirect("event_add.aspx" + ReturnQueryString(true) + "&eid=" + ((LinkButton)sender).CommandArgument, true);
    }

    protected void Img_click(object sender, EventArgs e)
    {
        Response.Redirect("event_img_list.aspx" + ReturnQueryString(true) + "&EventsID=" + ((LinkButton)sender).CommandArgument, true);
    }
    /*修改人：穆凤凤
        * 修改时间：2012-04-19
        * 修改内容：
        *      新增方法 绑定按姓名查找出来的活动记录 转到手机图片列表页
        *      有mff注释的为本次修改的代码
        */
    //mff
    protected void PhoneImg_click(object sender, EventArgs e)
    {
        Response.Redirect("phone_img_list.aspx" + ReturnQueryString(true) + "&EventsID=" + ((LinkButton)sender).CommandArgument, true);
    }//mff
    
    protected void Sponsor_click(object sender, EventArgs e)
    {
        Response.Redirect("Event_Sponsor_Logo.aspx" + ReturnQueryString(true) + "&EventsID=" + ((LinkButton)sender).CommandArgument, true);
    }
    protected void Video_click(object sender, EventArgs e)
    {
        Response.Redirect("event_video_list.aspx" + ReturnQueryString(true) + "&EventsID=" + ((LinkButton)sender).CommandArgument, true);
    }

    protected void Coment_click(object sender, EventArgs e)
    {
        Response.Redirect("event_comment_list.aspx" + ReturnQueryString(true) + "&EventsID=" + ((LinkButton)sender).CommandArgument, true);
    }
    //protected void Seo_click(object sender, EventArgs e)
    //{
    //    this.PopedomValidate(Request.Params["layerid"], MOD);
    //    Response.Redirect("info_seo.aspx?columnid=" + Request.Params["columnid"] + "&layerid=" + Request.Params["layerid"] + "&eid=" + ((LinkButton)sender).CommandArgument, true);
    //}

    //protected void Preview_click(object sender, EventArgs e)
    //{
    //    this.PopedomValidate(Request.Params["layerid"], QUERY);
    //    ClientScript.RegisterStartupScript(this.GetType(), "infopreview", "<script type='text/javascript'>window.open('info_preview.aspx?cid=" + Request.Params["columnid"] + "&aid=" + ((LinkButton)sender).CommandArgument + "','_blank');</script>");

    //}
    //protected void eventName_SelectedIndexChanged(object sender, EventArgs e)
    //{

    //}
}

